<!DOCTYPE html>
<html  lang="zh-CN" >
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=5, viewport-fit=cover">
    <title>在 Linux 上安装 sqlcmd 和 bcp SQL Server 命令行工具 | 学为我用</title>
    <meta name="description" content="通过以下步骤安装命令行工具、Microsoft ODBC 驱动程序及其依赖项。 mssql-tools 包包含：  sqlcmd：命令行查询实用工具。 bcp：批量导入-导出实用工具。  为你的平台安装工具：  Red Hat Enterprise Linux Ubuntu SUSE Linux Enterprise Server macOS  在 RHEL 8 上安装工具通过以下步骤在 Red">
<meta property="og:type" content="article">
<meta property="og:title" content="在 Linux 上安装 sqlcmd 和 bcp SQL Server 命令行工具">
<meta property="og:url" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/10/07/20201007162300-bcp-install/index.html">
<meta property="og:site_name" content="学为我用">
<meta property="og:description" content="通过以下步骤安装命令行工具、Microsoft ODBC 驱动程序及其依赖项。 mssql-tools 包包含：  sqlcmd：命令行查询实用工具。 bcp：批量导入-导出实用工具。  为你的平台安装工具：  Red Hat Enterprise Linux Ubuntu SUSE Linux Enterprise Server macOS  在 RHEL 8 上安装工具通过以下步骤在 Red">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-10-07T08:23:25.000Z">
<meta property="article:modified_time" content="2021-07-06T04:08:48.845Z">
<meta property="article:author" content="章瑱彬">
<meta property="article:tag" content="linux">
<meta name="twitter:card" content="summary">

    
    <link rel="icon" href="/zzbomb/images/favicon_128.ico" type="image/x-icon">

    
<link rel="stylesheet" href="/zzbomb/css/common.min.css">



    
    
    
    
        <link href="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/css/lightgallery.min.css" rel="stylesheet">
    
    
    
<link rel="stylesheet" href="/zzbomb/css/iconfont.min.css">

    
<meta name="generator" content="Hexo 4.2.1"></head>

    <body>
        <header class="header header-fixture">
    <div class="profile-search-wrap flex sm:block">
        
        
        <div class="profile sm:text-center md:px-1 lg:px-3 sm:pb-4 sm:pt-6">
            <a id="avatar" role="link" href="https://gitee.com/123zhangzhenbin" class="inline-block lg:w-16 lg:h-16 w-8 h-8 m-2" target="_blank" rel="noopener" rel="noreferrer" >
                <img src="/zzbomb/images/g.jpg" class="rounded-full" alt="avatar">
            </a>
            <h2 id="name" class="hidden lg:block">ZZB</h2>
            <h3 id="title" class="hidden xl:block">Java，大数据，人工智能，区块链</h3>
            
            <small id="location" class="hidden lg:block">
                <i class="iconfont icon-map-icon"></i>
                DongGuan, China
            </small>
            
        </div>
        
        
<div class="search flex-1 flex lg:inline-block sm:hidden lg:px-4 lg:mt-2 lg:mb-4 lg:w-full">
    <form id="search-form" class="my-auto flex-1 lg:border lg:border-solid lg:border-gray-200">
        <div class="input-group table bg-gray-100 lg:bg-white w-full">
            <input id="search-input" type="text" placeholder="搜索" class="inline-block w-full bg-gray-100 lg:bg-white">
            <span class="table-cell">
                <button name="search tigger button" disabled>
                    <i class="iconfont icon-search m-2"></i>
                </button>
            </span>
        </div>
    </form>
        
<script id="search-teamplate" type="text/html" data-path="/zzbomb/content.json">
    <div>
        <div class="search-header bg-gray-400">
            <input id="actual-search-input" model="keyword" ref="input" class="inline-block w-full h-10 px-2 py-1" placeholder="搜索" type="text">
        </div>
        <div class="search-result bg-gray-200">
            {{#each searchPosts}}
            <a href="/{{ path }}" class="result-item block px-2 pb-3 mb-1 pt-1 hover:bg-indigo-100">
                <i class="iconfont icon-file"></i>
                <h1 class="result-title inline font-medium text-lg">{{ title }}</h1>
                <p class="result-content text-gray-600 text-sm">{{{ text }}}</p>
            </a>
            {{/each}}
        </div>
    </div>
</script>

</div>


        <button name="menu toogle button" id="menu-toggle-btn" class="block sm:hidden p-3" role="button" aria-expanded="false">
            <i class="iconfont icon-hamburger"></i>
        </button>
    </div>
    <nav id="menu-nav" class="hidden sm:flex flex-col">
        
        
            <div class="menu-item menu-home" role="menuitem">
                <a href="/zzbomb/.">
                    <i class="iconfont icon-home" aria-hidden="true"></i>
                    <span class="menu-title">首页</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-archives" role="menuitem">
                <a href="/zzbomb/archives">
                    <i class="iconfont icon-archive" aria-hidden="true"></i>
                    <span class="menu-title">归档</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-categories" role="menuitem">
                <a href="/zzbomb/categories">
                    <i class="iconfont icon-folder" aria-hidden="true"></i>
                    <span class="menu-title">分类</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-tags" role="menuitem">
                <a href="/zzbomb/tags">
                    <i class="iconfont icon-tag" aria-hidden="true"></i>
                    <span class="menu-title">标签</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-repository" role="menuitem">
                <a href="/zzbomb/repository">
                    <i class="iconfont icon-project" aria-hidden="true"></i>
                    <span class="menu-title">项目</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-links" role="menuitem">
                <a href="/zzbomb/links">
                    <i class="iconfont icon-friend" aria-hidden="true"></i>
                    <span class="menu-title">友链</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-about" role="menuitem">
                <a href="/zzbomb/about">
                    <i class="iconfont icon-cup" aria-hidden="true"></i>
                    <span class="menu-title">关于</span>
                </a>
            </div>
        
        
<div class="social-links flex sm:flex-col lg:hidden mt-5">
    
        <span class="social-item text-center">
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont social-icon icon-github"></i>
                <span class="menu-title hidden lg:inline">menu.github</span>
            </a>
        </span>
    
</div>


    </nav>
</header>

        <section class="main-section">
            
    <main class="flex-1 px-4 py-12 md:px-5 lg:px-8 lg:py-4 relative min-h-screen">
    

    <article class="content article article-archives article-type-list" itemscope="">
        <header class="article-header">
            
    
        <h1 class="article-title text-lg" itemprop="name">
            在 Linux 上安装 sqlcmd 和 bcp SQL Server 命令行工具
        </h1>
    



            <p class="article-meta mb-3 text-xs">
                <span class="article-date">
    <i class="iconfont icon-calendar-check"></i>
	<a href="/zzbomb/2020/10/07/20201007162300-bcp-install/" class="article-date">
	  <time datetime="2020-10-07T08:23:25.000Z" itemprop="datePublished">10月 7</time>
	</a>
</span>

                

                
    <span class="article-tags">
    <i class="iconfont icon-tag"></i>
    <a class="article-tag-link" href="/zzbomb/tags/linux/" rel="tag">linux</a>
  </span>


                <span class="_partial/post-comment"><i class="icon icon-comment"></i>
                    <a href="/zzbomb/2020/10/07/20201007162300-bcp-install/#comments" class="article-comment-link">
                        评论
                    </a>
                </span>
                

            </p>
        </header>
        <div class="marked-body article-body">
            <p>通过以下步骤安装命令行工具、Microsoft ODBC 驱动程序及其依赖项。 mssql-tools 包包含：</p>
<ul>
<li>sqlcmd：命令行查询实用工具。</li>
<li>bcp：批量导入-导出实用工具。</li>
</ul>
<p>为你的平台安装工具：</p>
<ul>
<li>Red Hat Enterprise Linux</li>
<li>Ubuntu</li>
<li>SUSE Linux Enterprise Server</li>
<li>macOS</li>
</ul>
<h2 id="在-RHEL-8-上安装工具"><a href="#在-RHEL-8-上安装工具" class="headerlink" title="在 RHEL 8 上安装工具"></a>在 RHEL 8 上安装工具</h2><p>通过以下步骤在 Red Hat Enterprise Linux 上安装 mssql-tools。<br>进入超级用户模式。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs Bash"><span class="hljs-comment"># 进入超级用户模式</span><br>sudo su<br><span class="hljs-comment"># 下载</span><br>curl https://packages.microsoft.com/config/rhel/8/prod.repo &gt; /etc/yum.repos.d/msprod.repo<br><span class="hljs-comment"># 退出超级用户模式。</span><br><span class="hljs-built_in">exit</span><br><span class="hljs-comment"># 如果安装了早期版本的 mssql-tools，请删除所有旧的 unixODBC 包。</span><br>sudo yum remove mssql-tools unixODBC-utf16-devel<br><span class="hljs-comment"># 运行以下命令，以使用 unixODBC 开发人员包安装 mssql-tools。</span><br>sudo yum install mssql-tools unixODBC-devel<br><span class="hljs-comment"># 若要将 mssql-tools 更新至最新版本，请运行以下命令：</span><br>sudo yum check-update<br>sudo yum update mssql-tools<br><span class="hljs-comment"># 可选：向 bash shell 中的 PATH 环境变量添加 /opt/mssql-tools/bin/。</span><br><span class="hljs-comment"># 要使 sqlcmd/bcp 能从登陆会话的 bash shell 进行访问，请使用下列命令修改 ~/.bash_profile 文件中的 PATH ：</span><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bash_profile<br><span class="hljs-comment">#要使 sqlcmd/bcp 能从交互式/非登录会话的 bash shell 进行访问，请使用下列命令修改 ~/.bashrc 文件中的 PATH ：</span><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bashrc<br><span class="hljs-built_in">source</span> ~/.bashrc<br></code></pre></td></tr></table></figure>

<h2 id="在-Ubuntu-16-04-上安装工具"><a href="#在-Ubuntu-16-04-上安装工具" class="headerlink" title="在 Ubuntu 16.04 上安装工具"></a>在 Ubuntu 16.04 上安装工具</h2><p>通过以下步骤在 Ubuntu 上安装 mssql-tools。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs Bash"><span class="hljs-comment"># 导入公共存储库 GPG 密钥。</span><br>curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -<br><span class="hljs-comment">#注册 Microsoft Ubuntu 存储库。</span><br>curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list<br><span class="hljs-comment"># 更新源列表，并使用 unixODBC 开发人员包运行安装命令。</span><br>sudo apt-get update <br>sudo apt-get install mssql-tools unixodbc-dev<br><br><span class="hljs-comment">#若要将 mssql-tools 更新至最新版本，请运行以下命令：</span><br>sudo apt-get update <br>sudo apt-get install mssql-tools <br><span class="hljs-comment"># 可选：向 bash shell 中的 PATH 环境变量添加 /opt/mssql-tools/bin/。</span><br><span class="hljs-comment"># 要使 sqlcmd/bcp 能从登陆会话的 bash shell 进行访问，请使用下列命令修改 ~/.bash_profile 文件中的 PATH ：</span><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bash_profile<br><span class="hljs-comment"># 要使 sqlcmd/bcp 能从交互式/非登录会话的 bash shell 进行访问，请使用下列命令修改 ~/.bashrc 文件中的 PATH ：</span><br><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bashrc<br><span class="hljs-built_in">source</span> ~/.bashrc<br></code></pre></td></tr></table></figure>

<h2 id="在-SLES-12-上安装工具"><a href="#在-SLES-12-上安装工具" class="headerlink" title="在 SLES 12 上安装工具"></a>在 SLES 12 上安装工具</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 将 Microsoft SQL Server 存储库添加到 Zypper。</span><br>sudo zypper addrepo -<span class="hljs-built_in">fc</span> https://packages.microsoft.com/config/sles/12/prod.repo <br>sudo zypper --gpg-auto-import-keys refresh<br><span class="hljs-comment"># 使用 unixODBC 开发人员包安装 mssql-tools。</span><br>sudo zypper install mssql-tools unixODBC-devel<br><span class="hljs-comment"># 若要将 mssql-tools 更新至最新版本，请运行以下命令：</span><br>sudo zypper refresh<br>sudo zypper update mssql-tools<br><span class="hljs-comment"># 可选：向 bash shell 中的 PATH 环境变量添加 /opt/mssql-tools/bin/。</span><br><span class="hljs-comment"># 要使 sqlcmd/bcp 能从登陆会话的 bash shell 进行访问，请使用下列命令修改 ~/.bash_profile 文件中的 PATH ：</span><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bash_profile<br><span class="hljs-comment"># 要使 sqlcmd/bcp 能从交互式/非登录会话的 bash shell 进行访问，请使用下列命令修改 ~/.bashrc 文件中的 PATH ：</span><br><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="$PATH:/opt/mssql-tools/bin"'</span> &gt;&gt; ~/.bashrc<br><span class="hljs-built_in">source</span> ~/.bashrc<br></code></pre></td></tr></table></figure>

<h2 id="在-macOS-上安装工具"><a href="#在-macOS-上安装工具" class="headerlink" title="在 macOS 上安装工具"></a>在 macOS 上安装工具</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># macOS 上目前提供 sqlcmd 和 bcp 的预览版。</span><br><span class="hljs-comment"># 如果尚未安装 Homebrew，请进行安装：</span><br>/usr/bin/ruby -e <span class="hljs-string">"<span class="hljs-variable">$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)</span>"</span><br><span class="hljs-comment">#若要为 Mac El Capitan 和 Sierra 安装工具，请使用以下命令：</span><br><br><span class="hljs-comment"># brew untap microsoft/mssql-preview if you installed the preview version </span><br>brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release<br>brew update<br>brew install mssql-tools<br><span class="hljs-comment">#for silent install: </span><br><span class="hljs-comment">#HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=y brew install mssql-tools</span><br></code></pre></td></tr></table></figure>

        </div>
        
<blockquote class="copyright">
    <p><strong>本文链接 : </strong><a class="permalink" href="https://123zhangzhenbin.gitee.io/zzbomb/2020/10/07/20201007162300-bcp-install/">https://123zhangzhenbin.gitee.io/zzbomb/2020/10/07/20201007162300-bcp-install/</a></p>
    <p><strong>This article is available under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener noreferrer">Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a> License</strong></p>
</blockquote>


    </article>
    
    <section id="comments">
        
    </section>


    

</main>


<aside style="" id="sidebar" class="aside aside-fixture">
    <div class="toc-sidebar">
        <nav id="toc" class="article-toc">
            <h3 class="toc-title">文章目录</h3>
            <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#在-RHEL-8-上安装工具"><span class="toc-number">1.</span> <span class="toc-text">在 RHEL 8 上安装工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#在-Ubuntu-16-04-上安装工具"><span class="toc-number">2.</span> <span class="toc-text">在 Ubuntu 16.04 上安装工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#在-SLES-12-上安装工具"><span class="toc-number">3.</span> <span class="toc-text">在 SLES 12 上安装工具</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#在-macOS-上安装工具"><span class="toc-number">4.</span> <span class="toc-text">在 macOS 上安装工具</span></a></li></ol>
        </nav>
    </div>
</aside>





        </section>
        <footer class="hidden lg:block fixed bottom-0 left-0 sm:w-1/12 lg:w-1/6 bg-gray-100 z-40">
    
    <div class="footer-social-links">
        
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont icon-github"></i>
            </a>
        
    </div>
    
    <p style="display: block;text-align: center;font-size: 13px;"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
    
        <p class="footer-custom"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
        <p class="theme-brand">Theme by <a href="https://github.com/fengkx/hexo-theme-purer" target="_blank" rel="nofollow noopener noreferrer noopener">hexo-theme-purer</a></p>

    
</footer>

        <div id="mask" class="hidden mask fixed inset-0 bg-gray-900 opacity-75 z-40"></div>
        <div id="search-view-container" class="hidden shadow-xl"></div>
        
<script src="/zzbomb/js/dom-event.min.js"></script>

<script src="//cdn.jsdelivr.net/npm/yox@1.0.0-alpha.121/dist/standard/prod/yox.min.js"></script>


<script src="/zzbomb/js/search.min.js"></script>



    <script src="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/js/lightgallery.min.js"></script>
    
<script src="/zzbomb/js/light-gallery.min.js"></script>





    </body>
</html>
